package com.secret.chain.secretchain.mapper;

import com.secret.chain.secretchain.domain.entity.Group;
import org.apache.ibatis.annotations.*;

@Mapper
public interface GroupMapper {
    @Select("select * from `group` where id = #{id}")
    Group queryByCreatorId(Integer creatorId);
    @Insert("INSERT INTO `group` ( creator_id, group_name, avatar, user_number, introduction, create_time, status) VALUES(#{creatorId},#{groupName},#{avatar},#{userNumber},#{introduction},#{creatTime},#{status}) ")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(Group group);
    @Delete( "delete from `group` where id = #{id}")
    void deleteById(Integer id);
    @Update( "update `group` set creator_id = #{creatorId}, avatar=#{avatar},user_number=#{userNumber},group_name = #{groupName}, introduction = #{introduction}, status = #{status} WHERE id = #{id}")
    void put(Group group);
    @Select("SELECT * FROM `group` WHERE group_name LIKE CONCAT('%', #{keyword}, '%')")
    Group queryByKeyword(String keyword);
    @Select("select * from `group` where id = #{id}")
    Group queryById(Integer id);
    @Insert("INSERT INTO `group_user` ( group_id,user_id,role,status,create_time ) VALUES(#{id},#{creatorId},#{role},#{status},#{creatTime}) ")
    void insert1(Group group);
}
